﻿// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "SimpleCharacter.generated.h"

UCLASS()
class SIMPLE_API ASimpleCharacter : public ACharacter
{
	GENERATED_BODY()

public:

	ASimpleCharacter(const FObjectInitializer& ObjectInitializer);

	FORCEINLINE class UCameraComponent* GetCameraComponent() const { return CameraComponent; }

	FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; }

	FORCEINLINE class UHealthComponent* GetHealthComponent() const { return HealthComponent; }

	virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;

	virtual void PostInitializeComponents() override;

	virtual void Die(class APawn* InstigatedBy, AActor* DamageCauser);

	void OnDeath();

	UPROPERTY(Transient, Replicated)
	TWeakObjectPtr<class APawn> ShootBy;


	UPROPERTY(Transient, Replicated)
	TWeakObjectPtr<class AActor> DamageCa;

	bool bIsDying;

	uint8 bWantsToFire : 1;

	void StartWeaponFire();

	void StopWeaponFire();

	void OnStartFire();
protected:
	
	virtual void BeginPlay() override;

	UFUNCTION()
	void SpawnDefaultWeapon();

	void OnStopFire();
	
	void MoveForward(float Value);

	void MoveRight(float Value);

	UFUNCTION()
	void HandleOnHealthChanged(UHealthComponent* HealthComponent, float Health, float Damage, const class UDamageType* DamageType, class AController* InstigatedBy, AActor* DamageCauser);

	void RandomPlayerColor();

public:	
	virtual void Tick(float DeltaTime) override;

	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;

	UFUNCTION(NetMulticast, Reliable)
	void UpdatePlayerMaterials(UMaterialInterface* Material);

	UPROPERTY(Transient, Replicated, BlueprintReadOnly)
	class ASimpleWeapon* CurrentWeapon;

protected:

	UFUNCTION(BlueprintImplementableEvent, Category = Simple)
	void OnDeadBlueprintEvent();

	UPROPERTY(Category = Simple, VisibleAnywhere, BlueprintReadOnly)
	class UCameraComponent* CameraComponent;

	UPROPERTY(Category = Simple, VisibleAnywhere, BlueprintReadOnly)
	class USpringArmComponent* CameraBoom;

	UPROPERTY(Category = Simple, VisibleAnywhere, BlueprintReadOnly)
	class UHealthComponent* HealthComponent;

	UPROPERTY(EditDefaultsOnly, Category = Simple)
	TSubclassOf<class ASimpleWeapon> DefaultWeapon;

	UPROPERTY(EditDefaultsOnly, Category = Simple)
	UMaterialInterface* DieMaterial;
	
};
